package com.shanjupay.common.util;


import java.util.concurrent.TimeUnit;
import com.xkzhangsan.time.formatter.DateTimeFormatterUtil;
import com.xkzhangsan.time.nlp.TimeNLP;
import com.xkzhangsan.time.nlp.TimeNLPUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.*;

/**
 * 日期处理
 * 
 * @author alexgaoyh
 *
 */
public class TimeUtil {


	private static final Logger LOGGER = LoggerFactory.getLogger(QiniuUtils.class);

	private TimeUtil() {
	}


	/**
	 * 获得指定日期的前一天
	 *
	 * @param text
	 *
	 * @return
	 */
	public static String getTimeArr(String text) {

		List<TimeNLP> timeNLPList = TimeNLPUtil.parse(text);
		System.out.println(text);
		LOGGER.info(text);
		for (int i = 0; i < timeNLPList.size(); i++) {
			System.out.println("getLocalDateTime:" + timeNLPList.get(i).getLocalDateTime());
			System.out.println("对应格式getTimeExpression:" + timeNLPList.get(i).getTimeExpression());
			System.out.println("getTimeNormFormat:" + timeNLPList.get(i).getTimeNormFormat());
			System.out.println("对应时间 getTimeNorm:" + timeNLPList.get(i).getTimeNorm());
			System.out.println(" getTime:" + timeNLPList.get(i).getTime());
			System.out.println(" 转化getTime:" +  DateTimeFormatterUtil.formatToDateTimeStr(timeNLPList.get(0).getTime())  );
			System.out.println("getTimeContext:" + timeNLPList.get(i).getTimeContext());
		}
		return DateTimeFormatterUtil.formatToDateTimeStr(timeNLPList.get(0).getTime()).toString();
	}





	/**
	 * 获得指定日期的前一天
	 *
	 * @param text
	 *
	 * @return
	 */
	public static String parseConcurrent(String text) throws InterruptedException, ExecutionException, TimeoutException  {
		//2.限时30毫秒完成
		List<TimeNLP> timeNLPList = TimeNLPUtil.parseConcurrent(text, 30, TimeUnit.MILLISECONDS);
		System.out.println(text);
		System.out.println(DateTimeFormatterUtil.formatToDateTimeStr(timeNLPList.get(0).getTime()) + "-"
				+ timeNLPList.get(0).getIsAllDayTime());
		return DateTimeFormatterUtil.formatToDateTimeStr(timeNLPList.get(0).getTime()).toString();
	}




}
